package tihi.com.horizotalscrolldemo.base;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tihi on 2017/5/8.
 */

public class HAdapter<T extends AbsListItem> extends BaseAdapter {
	protected List<T> items;
	protected Context mContext;

	public HAdapter(Context context) {
		this(context, null);
	}

	public HAdapter(Context context, List<T> items) {
		this.items = (items != null) ? items : new ArrayList<T>();
		this.mContext = context;
	}
	
	public void setData(List<T> items) {
		this.items = (items != null) ? items : new ArrayList<T>();
		notifyDataSetChanged();
	}
	
	public List<T> getItems() {
		return items;
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		return items.get(position).getView(position, convertView, parent);
	}

}
